//测试Schlick的Fresnel的像素着色器

#version 450
#extension GL_ARB_separate_shader_objects : enable

//输入-从顶点着色器
layout(location = 0) in vec3 vs_fs_normal;
layout(location = 1) in vec2 vs_fs_TexCoord;
layout(location = 2) in vec3 vs_fs_worldPosition;

//输出
layout(location = 0) out vec4 fColor;

//纹理
layout(binding = 9) uniform samplerCube skyboxCubeMap;

//UniformBuffer
layout(binding = 7) uniform SceneData {
	mat4 view;
	mat4 proj;
	vec4 lightDir;
	vec4 eyePosition;
} ub_SceneData;

vec3 Fresnel_Schlick(vec3 F0, vec3 normal, vec3 view)
{
	float cosTheta = dot(normalize(view), normalize(normal));
	return F0 + (vec3(1, 1, 1) - F0) * pow(1 - cosTheta, 5);
}

void main()
{
	//测试的F0：
	vec3 TestF0 = vec3(0.25, 0.25, 0.25);
	//vec3 TestF0 = vec3(1.0, 0.886, 0.608);
	
	
	//视线方向
	vec3 ViewDir = ub_SceneData.eyePosition.xyz - vs_fs_worldPosition;
	
	//菲涅尔值
	vec3 Fresnel = Fresnel_Schlick(TestF0, vs_fs_normal, ViewDir);
	
	//镜面反射光的方向
	vec3 LightDir = reflect(normalize(ViewDir),normalize(vs_fs_normal));
	//采样的方向是光线方向的反向
	vec3 SampleDir = -LightDir;
	//采样立方体贴图获得颜色
	vec4 LightColor = texture(skyboxCubeMap, SampleDir);
	
	//直接输出菲涅尔值
	fColor = LightColor*vec4(Fresnel,1.0);
}
